package com.bawei.module_home.view

import android.os.Bundle
import android.view.Gravity
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.bawei.module_home.R
import com.bawei.module_home.adapter.PlayListAdapter
import com.bawei.module_home.databinding.FragmentCommentDialogBinding
import com.bawei.module_home.entriy.CommendEntity
import com.bawei.module_home.entriy.CommentHolder
import com.bawei.module_home.entriy.CommentListEntriyItem
import com.bawei.module_play.databinding.FragmentCommentBinding
import com.luck.picture.lib.utils.ToastUtils
import dagger.hilt.android.AndroidEntryPoint


@AndroidEntryPoint
class CommentDialogFragment : DialogFragment() {

    private var mDataBinding:FragmentCommentDialogBinding?=null
    private val binding get() = mDataBinding!!
    private var comments= listOf<CommentListEntriyItem>()


    override fun onStart() {
        super.onStart()
        dialog?.window?.apply {
            attributes=attributes.apply {
                dimAmount=0.3f
                gravity=Gravity.BOTTOM
            }
            //设置高度
            val matriics=resources.displayMetrics
            setLayout(matriics.widthPixels,(matriics.heightPixels*0.7).toInt())
        }
    }
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        mDataBinding=FragmentCommentDialogBinding.inflate(inflater,container,false)
        comments=CommentHolder.data
       // ToastUtils.showToast(this@CommentDialogFragment.context,comments.toString())

        dialog?.apply {
            setCanceledOnTouchOutside(false)
            window?.apply {
                setBackgroundDrawableResource(android.R.color.white)
                setCanceledOnTouchOutside(true)
                val lp=attributes
                attributes=lp
            }
        }
        return binding.root

    }


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        //显示评论列表
        binding.windowrv.apply {
            layoutManager= LinearLayoutManager(this@CommentDialogFragment.context,LinearLayoutManager.VERTICAL,false)
            adapter=PlayListAdapter(comments)
                .apply { notifyDataSetChanged() }
        }
        //发送评论
        binding.ivDanmuSend.setOnClickListener {

        }
    }

    override fun onDestroyView() {
        mDataBinding=null
        super.onDestroyView()
    }

}